<admintpl file="header" />
</head>
<body>
<div class="wrap">
	<ul class="nav nav-tabs">
		<li><a href="{:U('Distribution/index')}">配送时间列表</a></li>
		<li><a href="{:U('Distribution/add')}">添加配送时间</a></li>
		<li class="active"><a href="javascript:;">编辑配送时间</a></li>
	</ul>
	<form method="post" class="form-horizontal js-ajax-form" action="{:U('Distribution/edit_post')}">
		<fieldset>
			<div class="control-group">
				<label class="control-label"><b style="color:red;">* </b> 区域</label>
				<div class="controls">
					<select name="city_id" id="city_id" onchange="cityname()">
						<foreach name="city" item="vo">
							<option value="{$vo.city_id}" <if condition="$vo['city_id'] eq $dis['city_id']">selected</if>>{$vo.city_name}</option>
						</foreach>
						<input type="hidden" id="city_name" name="city_name" value="{$dis.city_name}">
					</select>
				</div>
			</div>
			<div class="control-group">
				<label class="control-label"><b style="color:red;">* </b> 截单时间</label>
				<div class="controls">
					<input type="text" id="time" name="time" placeholder="{$dis.time}">
				</div>
			</div>
			<div class="control-group">
				<label class="control-label"><b style="color:red;">* </b> 天数</label>
				<div class="controls">
					<input type="text" name="day" value="{$dis.day}">
				</div>
			</div>
			<div class="control-group" id="timediv">
				<label class="control-label"><b style="color:red;">* </b> 配送时间跨度</label>
				<if  condition="$dis['count_time'] gt 1 ">
					<div class="controls">
					<input type="text" class="distributiontime" name="start_time[]" placeholder="{$dis.start_time.0}" style="width: 80px;"> -
					<input type="text" class="distributiontime" name="end_time[]" placeholder="{$dis.end_time.0}" style="width: 80px;">
					<a class="btn btn-success" style="font-size: 20px;" onclick="addtime()">+</a>
					</div>
					<for start="1" end="$dis['count_time']">
						<div class="controls" style='margin-top: 10px'>
						<input type="text" class="distributiontime" name="start_time[]" placeholder="{$dis['start_time'][$i]}" style="width: 80px;"> -
						<input type="text" class="distributiontime" name="end_time[]" placeholder="{$dis['end_time'][$i]}" style="width: 80px;">
						<a class='btn btn-danger' style='font-size: 20px; width: 15px' onclick='deletediv(this)'>-</a>
						</div>
					</for>
					<else/>
					<div class="controls">
					<input type="text" class="distributiontime" name="start_time[]" placeholder="{$dis.start_time.0}" style="width: 80px;"> -
					<input type="text" class="distributiontime" name="end_time[]" placeholder="{$dis.end_time.0}" style="width: 80px;">
					<a class="btn btn-success" style="font-size: 20px;" onclick="addtime()">+</a>
					</div>
				</if>
			</div>
			<div class="control-group">
				<label class="control-label">{:L('STATUS')}</label>
				<div class="controls">
					<if condition="$dis.use_flg eq 1">
						<label class="radio inline" for="active_true"><input type="radio" name="use_flg" value="1" checked  />{:L('ENABLED')}</label>
						<label class="radio inline" for="active_false"><input type="radio" name="use_flg" value="0"  >{:L('DISABLED')}</label>
					<else />
						<label class="radio inline" for="active_true"><input type="radio" name="use_flg" value="1" />{:L('ENABLED')}</label>
						<label class="radio inline" for="active_false"><input type="radio" name="use_flg" value="0" checked >{:L('DISABLED')}</label>
					</if>
				</div>
			</div>
		</fieldset>
		<div class="form-actions">
			<input type="hidden" name="id" value="{$dis.id}">
			<button type="submit" class="btn btn-primary">{:L('EDIT')}</button>
			<a class="btn" href="javascript:history.back(-1);">{:L('BACK')}</a>
		</div>
	</form>
</div>
<script>
    function cityname(){
        var name = $("#city_id").find("option:selected").text();
        $("#city_name").val(name);
    }

    $("#time").datetimepicker({
        autoclose: true,
        maxView:1,
        startView: 1,
        language: 'zh-CN',
        format: 'hh:ii'
    })

    $(function () {
        $(".distributiontime").datetimepicker({
            autoclose: true,
            maxView:1,
            startView: 1,
            language: 'zh-CN',
            format: 'hh:ii'
        })
    })

    function addtime(){
        var text = "<div class='controls' style='margin-top: 10px'> <input type='text' class='distributiontime'  name='start_time[]' placeholder='开始时间' style='width: 80px;'> - <input type='text' class='distributiontime' name='end_time[]' placeholder='结束时间' style='width: 80px;'> <a class='btn btn-danger' style='font-size: 20px; width: 15px' onclick='deletediv(this)'>-</a> </div>";
        $("#timediv").append(text);
        $(".distributiontime").datetimepicker({
            autoclose: true,
            maxView:1,
            startView: 1,
            language: 'zh-CN',
            format: 'hh:ii'
        })
    }

    function deletediv(a){
        $(a).parent().remove();
    }


</script>
<script src="__PUBLIC__/js/common.js"></script>
</body>
</html>